//
//  LearnViewController.m
//  Hand shadow
//
//  Created by A-01 on 2020/7/20.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "LearnViewController.h"

@interface LearnViewController ()

@property (nonatomic, weak)UIView * blueView;
@property (nonatomic, weak)UIImageView * learnImageView;
@property (nonatomic, strong)UIButton * leftBtn;
@property (nonatomic, strong)UIButton * rightBtn;
@property (nonatomic, assign)int count;

@end

@implementation LearnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"Learn";
    self.count = 1;
    
    [self setupUI];
}


- (void)setupUI{

    UIView * blueView = [UIView new];
    
    blueView.backgroundColor = [UIColor colorWithHexString:@"BDE0F9"];
    
    self.blueView = blueView;
    
    [self.view addSubview:self.blueView];
    
    
    UIImageView * learnImageView = [UIImageView new];
    
    NSString * name = [NSString stringWithFormat:@"learn_%02d",self.count];
    learnImageView.image = [UIImage imageNamed:name];
    
    self.learnImageView = learnImageView;
    
    [self.view addSubview:self.learnImageView];
    
    
    self.leftBtn = [self setupButtonWithImg:@"left"];
    [self.view addSubview:self.leftBtn];
    self.rightBtn = [self setupButtonWithImg:@"right"];
    [self.view addSubview:self.rightBtn];
}


- (void)clickButton:(UIButton *)button{
    
    if (button == self.leftBtn) {
        if (self.count == 1) {

        }else{
            
           self.count --;
        }
    }else{
        
        if (self.count == 13) {
  
        }else{
            
           self.count ++;
        }
    }
    
    NSString * name = [NSString stringWithFormat:@"learn_%02d",self.count];
    self.learnImageView.image = [UIImage imageNamed:name];
}


- (void)viewDidLayoutSubviews{
        
    [super viewDidLayoutSubviews];
        
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(self.view);
        make.width.mas_equalTo(400);
        make.height.mas_equalTo(200);
    }];
    
    [self.learnImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(self.view);
    }];
    
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.blueView);
        make.trailing.mas_equalTo(self.blueView.mas_leading).offset(-25);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(24);
    }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.leftBtn);
        make.leading.mas_equalTo(self.blueView.mas_trailing).offset(25);
    }];
}


- (UIButton *)setupButtonWithImg:(NSString *)img{
    
    UIButton * button = [UIButton new];
    
    [button setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

@end
